package com.yyj.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yyj.dao.AuditDao;
import com.yyj.entity.Audit;
import com.yyj.entity.Params;
import com.yyj.entity.Pet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AuditService {
    @Autowired
    AuditDao auditDao;

    public void add(Audit audit) {
        auditDao.add(audit);
    }

    public PageInfo<Audit> getBySearch(Params params) {
        //开启分页查询
        PageHelper.startPage(params.getPageNum(), params.getPageSize());
        //裸数据 不包括数据总数,当前页和页面大小
        List<Audit> list = auditDao.getBySearch(params);
        for (Audit audit : list) {
            // 在这里对 audit 进行操作，例如打印或执行其他逻辑
            if (audit.getSpot() == null) {
                audit.setSpot("上门领养");
            }
        }

        //封装在一起的数据
        return PageInfo.of(list);
    }

    public List<Audit> getMyAudit(Integer applyUserId) {
        List<Audit> myAudit = auditDao.getMyAudit(applyUserId);
        for (Audit audit : myAudit) {
            // 在这里对 audit 进行操作，例如打印或执行其他逻辑
            if (audit.getSpot() == null) {
                audit.setSpot("上门领养");
            }
        }

        return myAudit;
    }

    public Audit getAPet(Integer petId) {
        Audit pet = auditDao.getAPet(petId);
        return pet;
    }

    public void check(Audit audit) {
        auditDao.check(audit);
    }

    public void delete(Integer auditId) {
        auditDao.delete(auditId);
    }

    public void update(Audit audit) {
        auditDao.update(audit);
    }

    //根据原宠物id查询
    public List<Audit> getReceive(Integer originalOwnerId) {
        List<Audit> all = auditDao.getReceive(originalOwnerId);
        return all;
    }

    public void setPet(Pet pet) {
        auditDao.setPet(pet);
    }

    public void setProgress() {
        auditDao.setProgress();
    }
}
